package com.heu.blood.autologous.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.heu.blood.common.aop.ControllerLogAnnotation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.heu.blood.autologous.entity.BloodInformationAutologousEntity;
import com.heu.blood.autologous.service.BloodInformationAutologousService;
import com.heu.blood.common.utils.PageUtils;
import com.heu.blood.common.utils.R;



/**
 * 
 *
 * @author lyj
 * @email lyj@heu.com
 * @date 2024-11-30 19:22:05
 */
@RestController
@RequestMapping("autologous/bloodinformationautologous")
public class BloodInformationAutologousController {
    @Autowired
    private BloodInformationAutologousService bloodInformationAutologousService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @ControllerLogAnnotation(module = "自体血模块", operate = "分页查询自体血血液信息表")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = bloodInformationAutologousService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @ControllerLogAnnotation(module = "自体血模块", operate = "根据ID查询自体血血液信息详情")
    public R info(@PathVariable("id") Long id){
		BloodInformationAutologousEntity bloodInformationAutologous = bloodInformationAutologousService.getById(id);

        return R.ok().put("bloodInformationAutologous", bloodInformationAutologous);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @ControllerLogAnnotation(module = "自体血模块", operate = "保存自体血血液信息")
    public R save(@RequestBody BloodInformationAutologousEntity bloodInformationAutologous){
		bloodInformationAutologousService.save(bloodInformationAutologous);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @ControllerLogAnnotation(module = "自体血模块", operate = "修改自体血血液信息")
    public R update(@RequestBody BloodInformationAutologousEntity bloodInformationAutologous){
		bloodInformationAutologousService.updateById(bloodInformationAutologous);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @ControllerLogAnnotation(module = "自体血模块", operate = "批量逻辑删除自体血血液信息")
    public R delete(@RequestBody Long[] ids){
		bloodInformationAutologousService.removeByIds(Arrays.asList(ids));
        return R.ok();
    }

    @RequestMapping("/getPendingBloodInformation")
    @ControllerLogAnnotation(module = "自体血模块", operate = "获取未发血的血液信息")
    public R getPendingBloodInformation(){
       List<BloodInformationAutologousEntity> pendingBloodList=bloodInformationAutologousService.getPendingBloodInformation();
           return R.ok().put("data",pendingBloodList);
    }


    @RequestMapping("/addBloodAutologousInformation")
    @ControllerLogAnnotation(module = "自体血模块", operate = "新增自体血血液信息并修改入库")
    public R addBloodAutologousInformation(@RequestBody BloodInformationAutologousEntity bloodInfo){
        boolean result=bloodInformationAutologousService.addBloodAutologousInformation(bloodInfo);
        if (result){
            return R.ok("自体血血液信息添加成功");
        }else{
            return R.error("自体血血液信息添加失败");
        }
    }

}
